package exceptionDemo2;

import java.util.HashMap;
import java.util.Map;

public class UserManage {
	private Map<String, User> users = new HashMap<String, User>() ;
	private int id = 1;
	
	public User reg(String email,String pwd) throws EmailExistException{
		if(users.containsKey(email)){
			throw new EmailExistException("用户已存在");
		}
		User user = new User(id++,email,pwd);
		users.put(email, user);
		return user;
	}
	
	public User login(String email,String pwd) throws EmailExistException, PwdException{
		if(!users.containsKey(email)){
			throw new EmailExistException("用户不存在");
		}
		User user = users.get(email);
		if(!user.getPwd().equals(pwd)){
			throw new PwdException("密码错误");
		}
		return user;
	}
	
	
	
	
	
	
}
